package hot;

public class Num238 {
    public int[] productExceptSelf(int[] nums) {
        int n = nums.length;
        int[] ans = new int[n];
        int p = 1,q = 1;
        for(int i = 0; i < n; i++) {
            ans[i] = p;
            p *= nums[i];
        }
        for(int i = n - 1; i >=0; i--) {
            ans[i] *= q;
            q *= nums[i];
        }
        return ans;
    }
}
